package com.gsy.springai.config;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;


import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {

//    配置会话记忆,直接使用注入的方式

    @Autowired
    private  ChatMemory chatMemory;
//    @Bean
//    private ChatMemory chatMemory(){
//        return new MessageWindowChatMemory();
//    }

//    配置会话客户端
    @Bean
    public ChatClient  chatClient(OllamaChatModel model, ChatMemory chatMemory){
        return  ChatClient
                .builder(model)
                //设定提示词
                .defaultSystem("你的名字叫做东小阳，请以东小阳的身份和语气回答问题。")
                //加入会话拦截
                .defaultAdvisors(new SimpleLoggerAdvisor())
                //加入会话记忆功能  直接无法使用，使用流式编程
                .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
                .build();

    }
}
